package com.jiutong.meipengdai.views.popwindow;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.amap.api.maps2d.model.Text;
import com.jiutong.meipengdai.R;
import com.jiutong.meipengdai.utils.ToastUtil;
import com.jiutong.meipengdai.utils.UIUtils;

public class MapBottonPopupWindow extends BasePopupWindow implements View.OnClickListener {

    private TextView tvHouseName;
    private TextView tvPrice;
    private TextView tvAddress;
    private TextView etArea;
    private Button btnPinggu;
    private OnPingGuBtnClickLister mLister;
    private TextView tvArea;
    private TextView tvPgPrice;
    private Button btnKeepPg;
    private TextView tvOtherPg;
    private LinearLayout llLiJiPg;
    private LinearLayout llKeepPg;

    public MapBottonPopupWindow(Context context) {
        super(context);
    }

    public TextView getEtArea() {
        return etArea;
    }

    public void setEtArea(TextView etArea) {
        this.etArea = etArea;
    }

    public TextView getTvHouseName() {
        return tvHouseName;
    }

    public void setTvHouseName(TextView tvHouseName) {
        this.tvHouseName = tvHouseName;
    }

    public TextView getTvPrice() {
        return tvPrice;
    }

    public void setTvPrice(TextView tvPrice) {
        this.tvPrice = tvPrice;
    }

    public TextView getTvAddress() {
        return tvAddress;
    }

    public void setTvAddress(TextView tvAddress) {
        this.tvAddress = tvAddress;
    }

    @Override
    public void initView() {
        tvHouseName = (TextView) mContainer.findViewById(R.id.tv_house_name);
        tvPrice = (TextView) mContainer.findViewById(R.id.tv_price);
        tvAddress = (TextView) mContainer.findViewById(R.id.tv_address);
        etArea = (TextView) mContainer.findViewById(R.id.et_area);
        btnPinggu = (Button) mContainer.findViewById(R.id.btn_pinggu);

        llLiJiPg = (LinearLayout) mContainer.findViewById(R.id.ll_liji_pg);
        llKeepPg = (LinearLayout) mContainer.findViewById(R.id.ll_keep_pg);
        tvArea = (TextView) mContainer.findViewById(R.id.tv_area);
        tvPgPrice = (TextView) mContainer.findViewById(R.id.tv_pg_price);
        tvOtherPg = (TextView) mContainer.findViewById(R.id.tv_other_pg);
        btnKeepPg = (Button) mContainer.findViewById(R.id.btn_keep_pg);
    }

    @Override
    public void initEvent() {
        btnPinggu.setOnClickListener(this);
        btnKeepPg.setOnClickListener(this);
        tvOtherPg.setOnClickListener(this);
    }

    @Override
    public View getContentView() {
        return mContainer.findViewById(R.id.pop);
    }

    @Override
    public int getLayoutId() {
        return R.layout.pop_map_botton;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_pinggu:
                if (TextUtils.isEmpty(etArea.getText().toString().trim())) {
                    ToastUtil.shortToast(mContext, "请填写房屋面积");
                    return;
                }

                UIUtils.hideKeyboard(mContext);

                mLister.onLiJiBtnClick();
                llLiJiPg.setVisibility(View.GONE);
                llKeepPg.setVisibility(View.VISIBLE);

                tvPgPrice.setText("" + Double.parseDouble(tvPrice.getText().toString()) * Double.parseDouble(etArea.getText().toString()));

                tvArea.setText(etArea.getText().toString().trim());
                break;

            case R.id.btn_keep_pg:
                mLister.onKeepPgclick();
                llLiJiPg.setVisibility(View.VISIBLE);
                llKeepPg.setVisibility(View.GONE);
                etArea.setText("");
                dismiss();
                break;

            case R.id.tv_other_pg:
                mLister.onOtherPgClick();
                dismiss();
                break;
        }
    }

    /**
     * 拿到pop内容距离顶部距离
     *
     * @return
     */
    public int getDistanceForScreen() {
        return getContentView().getTop();
    }

    public void setOnBtnClickLister(OnPingGuBtnClickLister lister) {
        this.mLister = lister;
    }

    public interface OnPingGuBtnClickLister {
        void onLiJiBtnClick();

        void onKeepPgclick();

        void onOtherPgClick();
    }
}
